package com.ouheng.common.task;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ouheng.shop.domain.OhOrderDO;
import com.ouheng.shop.service.OhOrderService;

/**
 * 订单完成定任务
 * ClassName: orderFinishJob 
 * @Description: TODO
 * @author zhanghui
 * @date 2018年9月27日
 */
@Component
public class orderFinishJob implements Job{
	
	@Autowired
	private OhOrderService ohOrderService;

    @Override
    public void execute(JobExecutionContext arg0) throws JobExecutionException {
    	//获取当前时间
        LocalDateTime localDateTime =LocalDateTime.now();
        System.out.println("当前时间为:" + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, -15);
//		c.add(Calendar.MINUTE, -1);
		Map<String, Object> map = new HashMap<>();
		map.put("modifydate", formatter.format(c.getTime()));
		System.out.println("当前时间为:" + formatter.format(c.getTime()));
		List<OhOrderDO> listOrder = ohOrderService.listReturnMoeny(map);
		
		//返佣
		for (OhOrderDO ohOrderDO : listOrder) {
			ohOrderService.finish(ohOrderDO.getId());
		}
    }

}